#!/usr/bin/env python
# -*- coding: utf-8 -*-
# author:Charles.chen
# createDate:2017/9/22
# Title:
# Tip:
import os

# 获取附近的wifi名称列表
# [nameA, nameB, nameC ]
def getAPSList():
    res_array = []
    with os.popen("iwpriv ra0 set SiteSurvey=1 && sleep 1 && iwpriv ra0 get_site_survey") as ps:
        res = ps.readlines()
        for i in res[3::]:
            sline = ' '.join(i.split())
            columns = sline.split(" ")
            if len(columns) >= 2 and columns[1] not in res_array:
                res_array.append(columns[1])
            pass
    return res_array
    pass

# 设置入网wifi
# TODO 设置入网的过程会导致当前ap失效 需要重新联入网络环境
def setAPSWifi(name=None, pwd=None):
    os.popen("setwifi {wifi} {pwd}".format(wifi=name, pwd=pwd))
    pass

# 检查当前网络状态 True有网 False无网
def checkInternetT():
    return1 = os.system('ping 8.8.8.8 -c 2')
    if return1:
        return False
    else:
        return True
    pass

# 检查云端网络是否可用
def checkInternet(remote=None):
    return1 = os.system('ping {address} -c 2'.format(address=remote))
    if return1:
        return False
    else:
        return True
    pass

if __name__ == '__main__':
    pass